package com.example.sjjg.utest

import android.app.Service
import com.example.sjjg.utest.model.MainIntentService
import com.example.sjjg.utest.model.MainService
import com.google.common.truth.Truth
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.android.controller.IntentServiceController
import org.robolectric.android.controller.ServiceController


@RunWith(RobolectricTestRunner::class)
class RobolectricService {
    @Test
    fun test_service(){

        // given
        val sc : ServiceController<MainService> = Robolectric.buildService(MainService::class.java)
        val service = sc.get()

        // when
        sc.rebind()
        //...
        sc.bind()
        //...
        sc.startCommand(Service.START_FLAG_REDELIVERY,++service.id)

        // then
        Truth.assertThat(service.id > 0)
        //...
        service.stopSelf()
    }
    @Test
    fun test_intent_service(){

        // given
        val sc : IntentServiceController<MainIntentService> = Robolectric.buildIntentService(
            MainIntentService::class.java)
        val service = sc.get()

        // when
        sc.handleIntent()

        // then
        Truth.assertThat(service.status)
        service.stopSelf()

    }
}